package com.example.teacher.util

import com.example.teacher.data.Course
import com.google.gson.Gson
import com.google.gson.JsonParser
import com.google.gson.reflect.TypeToken


object JsonUtil {
    fun JsonParse(data:String?):List<Course>{
        val res:List<Course> = Gson().fromJson(data, object :TypeToken<List<Course>>() {}.type)
        return res
    }

    inline fun <reified T> DataParse(data: String?):List<T>{
        val parser=JsonParser()
        val jsonArray=parser.parse(data).asJsonArray
        val gson=Gson()
        val dataBean=ArrayList<T>()
        for (jsonElement in jsonArray) {
            val res=gson.fromJson(jsonElement,T::class.java)
            dataBean.add(res)
        }
        return dataBean
    }

}